#include "Field.h"

#include <string.h>
#include <fan-llvm/core/Core.h>
#include "Type.h"
#include "UnsupportedErr.h"


Type* Field_classType = NULL;
VTable* Field_classVTable = NULL;


/**********************************************
 *
 * Methods and fields
 *
 **********************************************/


/* |Obj->Void| makeSetFunc([Field:Obj?] vals) */
Func* Field_makeSetFunc(Map* vals)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Field.makeSetFunc not implemented yet"));
}


/* Type type() */
Type* Field_type(Field* self)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Field.type not implemented yet"));
}


/* Obj? get(Obj? instance) */
NullableObj Field_get_0(Field* self)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Field.get not implemented yet"));
}


/* Obj? get(Obj? instance) */
NullableObj Field_get(Field* self, NullableObj instance)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Field.get not implemented yet"));
}


/* Void set(Obj? instance, Obj? value) */
void Field_set(Field* self, NullableObj instance, NullableObj value)
{
  exceptionThrow(UnsupportedErr_newWithFormattedMsg("sys::Field.set not implemented yet"));
}


/**********************************************
 *
 * Type-system functions
 *
 **********************************************/


Type* Field_initType(void)
{
  if (Field_classType == NULL)
  {
    Type* baseType = Slot_initType();
    VTable* vtable = Field_initVTable();
    Type* type = Type_new("Field", baseType, vtable, sizeof(Field), sizeof(FieldVTable));
    Type_registerMethodImplementation(type, "get", Field_get_0, 0);
    Type_registerMethodImplementation(type, "get", Field_get, 1);
    Type_registerMethodImplementation(type, "makeSetFunc", Field_makeSetFunc, 1);
    Type_registerMethodImplementation(type, "set", Field_set, 2);
    Type_registerMethodImplementation(type, "type", Field_type, 0);
    Field_classType = type;
    Field_initStatic();
  }
  return Field_classType;
}


VTable* Field_initVTable(void)
{
  if (Field_classVTable == NULL)
  {
    VTable* vtable = memoryAlloc(sizeof(FieldVTable));
    memcpy(vtable, Slot_initVTable(), sizeof(SlotVTable));
    ((FieldVTable*)vtable)->get_0 = Field_get_0;
    ((FieldVTable*)vtable)->get = Field_get;
    ((FieldVTable*)vtable)->set = Field_set;
    Field_classVTable = vtable;
  }
  return Field_classVTable;
}


void Field_initStatic(void)
{
}
